

package com.ourteam.education.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.ourteam.education.dao.ClassDefine;
import com.ourteam.education.dao.ClassDefineDAOQueryBean;
import com.ourteam.education.dao.IClassDefineDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-09-22 15:15:12
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractClassDefineDAOJdbcImpl 
    extends AbstractSpringDAO implements IClassDefineDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
						
			
			
								
			
			
								
			
			
				
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,CampusId,CourseId,ClassName,FullClassNumber,MinClassNumber,EnrollmentStatus,ClassRoomId,StartClassDate,EndClassDate,StudentClassHour,TeacherClassHour,DeleteFlag,Status,Remarks,CampusName,CourseName,ClassroomName };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.CampusId,_DataObjectProperty.CourseId,_DataObjectProperty.ClassName,_DataObjectProperty.FullClassNumber,_DataObjectProperty.MinClassNumber,_DataObjectProperty.EnrollmentStatus,_DataObjectProperty.ClassRoomId,_DataObjectProperty.StartClassDate,_DataObjectProperty.EndClassDate,_DataObjectProperty.StudentClassHour,_DataObjectProperty.TeacherClassHour,_DataObjectProperty.DeleteFlag,_DataObjectProperty.Status,_DataObjectProperty.Remarks,_DataObjectProperty.CampusName,_DataObjectProperty.CourseName,_DataObjectProperty.ClassroomName};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<ClassDefine, ClassDefineDAOQueryBean> daoHelper;
	
	public AbstractClassDefineDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<ClassDefine, ClassDefineDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQLbuffer.append(DeleteFlag).append("=  0  ");
			
						
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.ICampusDAO.EntityName)
                .append(" RELATED_U745CW_Campus ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICampusDAO.Id,com.ourteam.education.dao.ICampusDAO.EntityName + ".","RELATED_U745CW_Campus."));
				relatedJoinSQLBuffer.append(" = ").append(CampusId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICampusDAO.DeleteFlag,com.ourteam.education.dao.ICampusDAO.EntityName + ".", "RELATED_U745CW_Campus.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.ICourseDefineDAO.EntityName)
                .append(" RELATED_Z25GSZ_CourseDefine ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseDefineDAO.Id,com.ourteam.education.dao.ICourseDefineDAO.EntityName + ".","RELATED_Z25GSZ_CourseDefine."));
				relatedJoinSQLBuffer.append(" = ").append(CourseId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseDefineDAO.DeleteFlag,com.ourteam.education.dao.ICourseDefineDAO.EntityName + ".", "RELATED_Z25GSZ_CourseDefine.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.IClassroomDAO.EntityName)
                .append(" RELATED_IMNMKQ_Classroom ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.IClassroomDAO.Id,com.ourteam.education.dao.IClassroomDAO.EntityName + ".","RELATED_IMNMKQ_Classroom."));
				relatedJoinSQLBuffer.append(" = ").append(ClassRoomId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.IClassroomDAO.DeleteFlag,com.ourteam.education.dao.IClassroomDAO.EntityName + ".", "RELATED_IMNMKQ_Classroom.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aClassDefine
	 * @throws Exception
	 */
	public boolean checkIsUnique(ClassDefine aClassDefine) throws Exception{
	
		if(aClassDefine == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aClassDefine.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aClassDefine
	 * @throws Exception
	 */
	public void insert(ClassDefine aClassDefine) throws Exception{
		
						
		PropertyUtils.setProperty(aClassDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("0",int.class));
				
				
		super.doInsert(aClassDefine);

	}

    /**
	 * Batch Insert Datas
	 * @param aClassDefine
	 * @throws Exception
	 */
	public void batchInsert(ClassDefine[] aClassDefines) throws Exception{
		
		 super.doBatchInsert(aClassDefines);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
		ClassDefine tempClassDefine = findById( id);
		
						
		PropertyUtils.setProperty(tempClassDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempClassDefine);
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(ClassDefineDAOQueryBean queryBean) throws Exception{
	
				
		ClassDefine tempClassDefine = new ClassDefine();
		
				
				
	    PropertyUtils.setProperty(tempClassDefine,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempClassDefine,queryBean);
				
	}
	
	public void delete(ClassDefine aClassDefine) throws Exception {
				
				
									
						
					
				
		delete(aClassDefine.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aClassDefine
	 * @throws Exception
	 */
	public void update(ClassDefine aClassDefine) throws Exception{
		
						
											
				
				
		if(aClassDefine.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aClassDefine);
		
		ClassDefine tempObj = findById(aClassDefine.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aClassDefine, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aClassDefines[]
	 * @throws Exception
	 */
	public void batchUpdate(ClassDefine[] aClassDefines) throws Exception{
		
		super.doBatchUpdate(aClassDefines);

	}

    /**
	 * Update Data By Condictions
	 * @param aClassDefine
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(ClassDefine aClassDefine, ClassDefineDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aClassDefine, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(ClassDefineDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(ClassDefine aClassDefine) throws Exception{	
																																																																																					
		if(aClassDefine.getCampusName() == null){
			throw new Exception("The ClassDefine.campusName value is not allow NULL");
		}
													
		if(aClassDefine.getCourseName() == null){
			throw new Exception("The ClassDefine.courseName value is not allow NULL");
		}
													
		if(aClassDefine.getClassroomName() == null){
			throw new Exception("The ClassDefine.classroomName value is not allow NULL");
		}
								
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public ClassDefine findById( final long id) throws Exception{
		
		    	                
    	    	                		
		ClassDefineDAOQueryBean queryBean = new ClassDefineDAOQueryBean();
		
		ClassDefineDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		ClassDefine[] ClassDefines = query(queryBean);
		
		if(ClassDefines.length == 0){
			return null;
		}
		else{
			return ClassDefines[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return ClassDefine[]
	 * @throws Exception
	 */
	public ClassDefine[] query(ClassDefineDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcClassDefineRowMapper());

		return (ClassDefine[]) result.toArray(new ClassDefine[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(ClassDefineDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(ClassDefineDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(ClassDefine[] aClassDefines, ClassDefineDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aClassDefines,queryBean);
		
	}

	public void synchronize(ClassDefine[] aClassDefines,
			ClassDefineDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<ClassDefine> callBack)
			throws Exception {
		daoHelper.synchronize(aClassDefines,queryBean,callBack);
	}

    
     public static class JdbcClassDefineRowMapper implements
			RowMapper<ClassDefine> {

		public ClassDefine mapRow(ResultSet resultSet, int arg1) throws SQLException {
			ClassDefine object = new ClassDefine();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object campusId = null;
				
								
				campusId =  resultSet.getObject(columnIndex++);
				
				               
				object.setCampusIdNull(resultSet.getBoolean(columnIndex++));
				
				if(campusId != null){
				
                    setBeanValue(object, _DataObjectProperty.CampusId,campusId);
				}
				
					
	            	            
				Object courseId = null;
				
								
				courseId =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseIdNull(resultSet.getBoolean(columnIndex++));
				
				if(courseId != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseId,courseId);
				}
				
					
	            	            
				Object className = null;
				
								
				className =  resultSet.getObject(columnIndex++);
				
				               
				object.setClassNameNull(resultSet.getBoolean(columnIndex++));
				
				if(className != null){
				
                    setBeanValue(object, _DataObjectProperty.ClassName,className);
				}
				
					
	            	            
				Object fullClassNumber = null;
				
								
				fullClassNumber =  resultSet.getObject(columnIndex++);
				
				               
				object.setFullClassNumberNull(resultSet.getBoolean(columnIndex++));
				
				if(fullClassNumber != null){
				
                    setBeanValue(object, _DataObjectProperty.FullClassNumber,fullClassNumber);
				}
				
					
	            	            
				Object minClassNumber = null;
				
								
				minClassNumber =  resultSet.getObject(columnIndex++);
				
				               
				object.setMinClassNumberNull(resultSet.getBoolean(columnIndex++));
				
				if(minClassNumber != null){
				
                    setBeanValue(object, _DataObjectProperty.MinClassNumber,minClassNumber);
				}
				
					
	            	            
				Object enrollmentStatus = null;
				
								
				enrollmentStatus =  resultSet.getObject(columnIndex++);
				
				               
				object.setEnrollmentStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(enrollmentStatus != null){
				
                    setBeanValue(object, _DataObjectProperty.EnrollmentStatus,enrollmentStatus);
				}
				
					
	            	            
				Object classRoomId = null;
				
								
				classRoomId =  resultSet.getObject(columnIndex++);
				
				               
				object.setClassRoomIdNull(resultSet.getBoolean(columnIndex++));
				
				if(classRoomId != null){
				
                    setBeanValue(object, _DataObjectProperty.ClassRoomId,classRoomId);
				}
				
					
	            	            
				Object startClassDate = null;
				
								
				__dataType = resultSet.getMetaData().getColumnType(columnIndex);
				
				if(__dataType == java.sql.Types.DATE || __dataType == java.sql.Types.TIME || __dataType == java.sql.Types.TIMESTAMP){
					startClassDate = resultSet.getTimestamp(columnIndex++);
				
				}
				else{
					startClassDate =  resultSet.getObject(columnIndex++);
				
				}
				
				               
				object.setStartClassDateNull(resultSet.getBoolean(columnIndex++));
				
				if(startClassDate != null){
				
                    setBeanValue(object, _DataObjectProperty.StartClassDate,startClassDate);
				}
				
					
	            	            
				Object endClassDate = null;
				
								
				__dataType = resultSet.getMetaData().getColumnType(columnIndex);
				
				if(__dataType == java.sql.Types.DATE || __dataType == java.sql.Types.TIME || __dataType == java.sql.Types.TIMESTAMP){
					endClassDate = resultSet.getTimestamp(columnIndex++);
				
				}
				else{
					endClassDate =  resultSet.getObject(columnIndex++);
				
				}
				
				               
				object.setEndClassDateNull(resultSet.getBoolean(columnIndex++));
				
				if(endClassDate != null){
				
                    setBeanValue(object, _DataObjectProperty.EndClassDate,endClassDate);
				}
				
					
	            	            
				Object studentClassHour = null;
				
								
				studentClassHour =  resultSet.getObject(columnIndex++);
				
				               
				object.setStudentClassHourNull(resultSet.getBoolean(columnIndex++));
				
				if(studentClassHour != null){
				
                    setBeanValue(object, _DataObjectProperty.StudentClassHour,studentClassHour);
				}
				
					
	            	            
				Object teacherClassHour = null;
				
								
				teacherClassHour =  resultSet.getObject(columnIndex++);
				
				               
				object.setTeacherClassHourNull(resultSet.getBoolean(columnIndex++));
				
				if(teacherClassHour != null){
				
                    setBeanValue(object, _DataObjectProperty.TeacherClassHour,teacherClassHour);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
								
				            	            	            					            	            	
	            	            
				Object campusName = null;
				
								
				campusName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCampusNameNull(resultSet.getBoolean(columnIndex++));
				
				if(campusName != null){
				
                    setBeanValue(object, _DataObjectProperty.CampusName,campusName);
				}
				
												            	            	            					            	            	
	            	            
				Object courseName = null;
				
								
				courseName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseNameNull(resultSet.getBoolean(columnIndex++));
				
				if(courseName != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseName,courseName);
				}
				
												            	            	            					            	            	
	            	            
				Object classroomName = null;
				
								
				classroomName =  resultSet.getObject(columnIndex++);
				
				               
				object.setClassroomNameNull(resultSet.getBoolean(columnIndex++));
				
				if(classroomName != null){
				
                    setBeanValue(object, _DataObjectProperty.ClassroomName,classroomName);
				}
				
																
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}